package com.qzdsoft.erpcloud.controller.sys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qzdsoft.erpcloud.service.sys.SysUserBindService;
import com.qzdsoft.erpcloud.vo.sys.SysUserBindQueryParam;
import com.qzdsoft.utils.SysUtils;
import com.qzdsoft.vo.DataTablePo;
import com.qzdsoft.vo.EnumPo;
import com.qzdsoft.vo.sys.SysUserBindAccountTypeEnum;

/**
 * Created by Admin
 */
@Controller
@RequestMapping("/sys/user/bind")
public class SysUserBindController {

    @Autowired
    private SysUserBindService sysUserBindService;

    @RequestMapping("/index")
    public Object index(HttpServletRequest request, Model model) {
        List<EnumPo> accountTypeList = new ArrayList<EnumPo>();
        Map<Object, Object> accountTypeMap = new HashMap<Object, Object>();
        for(SysUserBindAccountTypeEnum e : SysUserBindAccountTypeEnum.values()){
            SysUtils.enums(accountTypeList, accountTypeMap, e.getKey(), e.getVal());
        }

        model.addAttribute("accountTypeList", accountTypeList);
        model.addAttribute("accountTypeMap", accountTypeMap);
        return "sys/user_bind";
    }

    @ResponseBody
    @RequestMapping("/data")
    public Object data(HttpServletRequest request, SysUserBindQueryParam param) {
        Integer count = sysUserBindService.selectDataCount(param.getAccount(), param.getAccountType(), param.getAccountName());
        List list = sysUserBindService.selectData(param.getAccount(), param.getAccountType(), param.getAccountName(), param.getiDisplayStart(), param.getiDisplayLength());
        return new DataTablePo(count, list, param.getsEcho());
    }

}
